<?php
class CustomerModel extends Model
{
    public function getUsers(array $conditions)
    {

    }

    public function getCustomerById($customerId)
    {
        return $this->_db->fetchRow('
            SELECT *
            FROM customer
            WHERE customer_id = ?
        ', $customerId);
    }

    public function login($email, $password)
    {
        $whereClause = $this->prepareUserConditions(array(
            'email' => $email,
            'password' => $password
        ));

        return $this->_db->fetchRow("
            SELECT customer_id, name, email
            FROM customer
            WHERE ". $whereClause ."
            LIMIT 0,1
        ");
    }

    public function prepareUserConditions(array $conditions)
    {
        $sqlConditions = array();

        if (!empty($conditions['email']))
        {
            $sqlConditions[] = 'customer.email = ' . $this->_db->quoteLike($conditions['email']);
        }

        if (!empty($conditions['password']))
        {
            $sqlConditions[] = 'customer.password = ' . $this->_db->quoteLike(md5($conditions['password']));
        }

        return $this->_db->getConditionsForClause($sqlConditions);
    }

    public function update(array $customer)
    {
        $this->_update('customer', $customer, 'customer_id');
    }
}